<!--
  
   TechObjectEditor.xaml
  
   Copyright (c) 2007 Mike Strobel
  
   This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
   For details, see <http://www.opensource.org/licenses/ms-rl.html>.
  
   All other rights reserved.
  
  -->
<local:EditorBase x:Class="Supremacy.Editor.TechObjectEditor"
             xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
             xmlns:local="clr-namespace:Supremacy.Editor"
             xmlns:tech="clr-namespace:Supremacy.Tech;assembly=SupremacyCore"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <local:EditorBase.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
  </local:EditorBase.Resources>

  <DockPanel LastChildFill="True"
             VerticalAlignment="Stretch">
    <Grid DockPanel.Dock="Right"
          MinWidth="128"
          Width="192"
          MaxWidth="256"
          Margin="0,12,12,0"
          VerticalAlignment="Stretch">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        
        <!-- Prerequisites -->
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>

        <!-- Obsoleted Items -->
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>

        <!-- Upgrades -->
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>

      <CheckBox Grid.Row="0"
                Content="Is buildable by all civilizations"
                IsChecked="{Binding Path=IsUniversallyAvailable}"/>
      
      <ToolBarTray Grid.Row="1"
                   ToolBarTray.IsLocked="True"
                   Margin="0,12,0,0">
        <ToolBar>
          <Label Content="Prerequisites"
                 FontWeight="Bold"/>
          <Button Click="AddPrerequisiteGroup">
            <Image Source="Resources/AddTableHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
          <Button Click="AddPrerequisite">
            <Image Source="Resources/NewDocumentHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
          <Button Click="DeletePrerequisite">
            <Image Source="Resources/DeleteHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
        </ToolBar>
      </ToolBarTray>
      <TreeView x:Name="PrerequisitesTree"
                Grid.Row="2"
                Height="80"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Auto">
        <TreeView.Resources>
          <Style TargetType="{x:Type TreeViewItem}"
                 BasedOn="{StaticResource {x:Type TreeViewItem}}">
            <Setter Property="IsExpanded"
                    Value="True" />
          </Style>
        </TreeView.Resources>
        <TreeView.ItemTemplate>
          <HierarchicalDataTemplate ItemsSource="{Binding}">
            <HierarchicalDataTemplate.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Path=Name}" />
              </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
            <TextBlock Text="(Prerequisite Group)" /> 
          </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
      </TreeView>

      <ToolBarTray Grid.Row="3"
                   ToolBarTray.IsLocked="True"
                   Margin="0,12,0,0">
        <ToolBar>
          <Label Content="Obsoleted Items"
                 FontWeight="Bold"/>
          <Button Click="AddObsoletedItem">
            <Image Source="Resources/NewDocumentHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
          <Button Click="DeleteObsoletedItem">
            <Image Source="Resources/DeleteHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
        </ToolBar>
      </ToolBarTray>
      <ListView x:Name="ObsoletedItemList"
                Grid.Row="4"
                Height="80"
                ItemsSource="{Binding Path=ObsoletedDesigns}"
                ItemTemplate="{StaticResource TechObjectNameTemplate}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Auto"/>

      <ToolBarTray Grid.Row="5"
                   ToolBarTray.IsLocked="True"
                   Margin="0,12,0,0">
        <ToolBar>
          <Label Content="Upgrade Options"
                 FontWeight="Bold"/>
          <Button Click="AddUpgradeOption">
            <Image Source="Resources/NewDocumentHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
          <Button Click="DeleteUpgradeOption">
            <Image Source="Resources/DeleteHS.png"
                   Width="16"
                   Height="16"/>
          </Button>
        </ToolBar>
      </ToolBarTray>
      <ListView x:Name="UpgradeList"
                Grid.Row="6"
                Height="80"
                ItemsSource="{Binding Path=UpgradableDesigns}"
                ItemTemplate="{StaticResource TechObjectNameTemplate}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Auto"/>
    </Grid>


    <Grid DockPanel.Dock="Left"
          Margin="12,12,12,0">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"
                          SharedSizeGroup="EditorLeftColumnGroup" />
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>

      <Label Grid.Column="0"
             Grid.Row="0"
             Margin="0,3,2,3"
             Target="{Binding ElementName=IdentityText}"
             Content="Identity:"
             FontWeight="Bold"/>
      <TextBox x:Name="IdentityText"
               Grid.Column="1"
               Grid.Row="0"
               Margin="2,3,2,3"
               CharacterCasing="Upper">
        <TextBox.Text>
          <Binding Path="Key"
                   Mode="TwoWay">
            <Binding.ValidationRules>
              <local:NonEmptyValidationRule/>
            </Binding.ValidationRules>
          </Binding>
        </TextBox.Text>
      </TextBox>
      <Label Grid.Column="0"
             Grid.Row="1"
             Margin="0,3,2,3"
             Target="{Binding ElementName=NameText}"
             Content="Name:"
             FontWeight="Bold"/>
      <DockPanel LastChildFill="True"
                 Grid.Column="1"
                 Grid.Row="1"
                 Margin="2,3,2,3">
        <Button x:Name="LocalizeNamesButton"
                DockPanel.Dock="Right"
                Margin="6,0,0,0"
                Content="..."
                Click="LocalizeNamesButton_Click" />
        <TextBox Name="NameText">
          <TextBox.Text>
            <Binding Path="Name"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule />
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
      </DockPanel>
      <Label Grid.Column="0"
             Grid.Row="2"
             Margin="0,3,2,3"
             Target="{Binding ElementName=DescriptionText}"
             Content="Description:"
             FontWeight="Bold"/>
      <DockPanel LastChildFill="True"
                 Grid.Column="1"
                 Grid.Row="2"
                 Margin="2,3,2,3">
        <Button x:Name="LocalizeDescriptionButton"
                DockPanel.Dock="Right"
                Margin="6,0,0,0"
                Content="..."
                Click="LocalizeDescriptionButton_Click"
                VerticalAlignment="Top" />
        <TextBox Name="DescriptionText"
                 Height="64"
                 TextWrapping="Wrap"
                 VerticalScrollBarVisibility="Visible"
                 AcceptsReturn="True"
                 Text="{Binding Path=Description, Mode=TwoWay}" />
      </DockPanel>
      <Label Grid.Column="0"
             Grid.Row="3"
             Margin="0,3,2,3"
             Target="{Binding ElementName=BuildCostText}"
             Content="Build Cost:"
             FontWeight="Bold"/>
      <TextBox Name="BuildCostText"
               Grid.Column="1"
               Grid.Row="3"
               Width="64"
               Margin="2,3,2,3"
               HorizontalAlignment="Left">
        <TextBox.Text>
          <Binding Path="BuildCost"
                   Mode="TwoWay">
            <Binding.ValidationRules>
              <local:NonEmptyValidationRule/>
              <local:RangeValidationRule Min="0"/>
            </Binding.ValidationRules>
          </Binding>
        </TextBox.Text>
      </TextBox>
      <Label Grid.Column="0"
             Grid.Row="4"
             Margin="0,3,2,3"
             Target="{Binding ElementName=MaintenanceCostText}"
             Content="Upkeep Cost:"
             FontWeight="Bold"/>
      <TextBox Name="MaintenanceCostText"
               Grid.Column="1"
               Grid.Row="4"
               Width="64"
               Margin="2,3,2,3"
               HorizontalAlignment="Left">
        <TextBox.Text>
          <Binding Path="MaintenanceCost"
                   Mode="TwoWay">
            <Binding.ValidationRules>
              <local:NonEmptyValidationRule/>
              <local:RangeValidationRule Min="0"/>
            </Binding.ValidationRules>
          </Binding>
        </TextBox.Text>
      </TextBox>
      <StackPanel Grid.Column="0"
                  Grid.Row="5"
                  Margin="5,3,2,3"
                  Orientation="Vertical">
        <TextBlock Text="Image Preview:"
                   FontWeight="Bold" />
        <TextBlock x:Name="ImageLinkSourceBlock"
                   Visibility="{Binding Path=IsImageLinked, Converter={StaticResource BooleanToVisibilityConverter}}"
                   TextWrapping="Wrap"
                   TextTrimming="CharacterEllipsis">
          <TextBlock Text="&#x2192;" />
          <TextBlock Text="{Binding Path=ImageLinkSource.Name, Converter={StaticResource StringResourceConverter}}" />
        </TextBlock>
        <TextBlock x:Name="ResetImageBlock"
                   Visibility="{Binding Path=IsImageDefined, Converter={StaticResource BooleanToVisibilityConverter}}">
          <Hyperlink x:Name="ResetImageButton"
                     Click="ResetImageButton_Click">Reset Image</Hyperlink>
        </TextBlock>
        <TextBlock x:Name="SelectImageBlock"
                   Visibility="{Binding Path=IsImageAutomatic, Converter={StaticResource BooleanToVisibilityConverter}}">
          <Hyperlink x:Name="SelectImageButton"
                     Click="SelectImageButton_Click">Select Image</Hyperlink>
        </TextBlock>
        <TextBlock x:Name="LinkImageBlock"
                   Visibility="{Binding Path=IsImageAutomatic, Converter={StaticResource BooleanToVisibilityConverter}}">
          <Hyperlink x:Name="LinkImageButton"
                     Click="LinkImageButton_Click">Link Image</Hyperlink>
        </TextBlock>
      </StackPanel>
      <Border Grid.Column="1"
              Grid.Row="5"
              MinWidth="54"
              MinHeight="45"
              Margin="2,3,2,3"
              Background="Black"
              HorizontalAlignment="Left"
              VerticalAlignment="Top">
        <Image x:Name="ImagePreview"
               MaxWidth="270"
               MaxHeight="225"
               Source="{Binding Path=Image, Converter={StaticResource TechObjectImageConverter}}"
               Stretch="Uniform"
               StretchDirection="Both"/>
      </Border>

      <!-- TECH REQUIREMENTS -->
      <Grid Grid.Column="2"
            Grid.Row="0"
            Grid.RowSpan="6"
            Margin="12,0,6,0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Label Grid.Column="0"
               Grid.ColumnSpan="2"
               Grid.Row="0"
               Margin="2,0,2,3"
               HorizontalAlignment="Center"
               FontWeight="Bold"
               Content="Tech Requirements"/>
        <!-- BioTech -->
        <Label Grid.Column="0"
               Grid.Row="1"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.BioTech}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="1"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[BioTech]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
        <!-- Computer -->
        <Label Grid.Column="0"
               Grid.Row="2"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.Computers}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="2"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[Computers]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
        <!-- Construction -->
        <Label Grid.Column="0"
               Grid.Row="3"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.Construction}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="3"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[Construction]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
        <!-- Energy -->
        <Label Grid.Column="0"
               Grid.Row="4"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.Energy}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="4"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[Energy]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
        <!-- Propulsion -->
        <Label Grid.Column="0"
               Grid.Row="5"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.Propulsion}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="5"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[Propulsion]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
        <!-- Weapons -->
        <Label Grid.Column="0"
               Grid.Row="6"
               Margin="2,3,2,3"
               Content="{x:Static tech:TechCategory.Weapons}"/>
        <TextBox Grid.Column="1"
                 Grid.Row="6"
                 HorizontalAlignment="Left"
                 Width="24"
                 Margin="2,3,2,3">
          <TextBox.Text>
            <Binding Path="TechRequirements[Weapons]"
                     Mode="TwoWay">
              <Binding.ValidationRules>
                <local:NonEmptyValidationRule/>
                <local:RangeValidationRule Min="0"
                                           Max="255"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>
      </Grid>
    </Grid>
  </DockPanel>
</local:EditorBase>
